/*
 * @Author: liruilin 1443254530@qq.com
 * @Date: 2023-11-22 14:02:26
 * @LastEditors: liruilin 1443254530@qq.com
 * @LastEditTime: 2023-12-04 14:01:07
 * @FilePath: uniapp-template\libs\index.js
 * @Description: 
 */

import EvnConfig from '@/libs/config/evn.config.js'
import AssetsConfig from '@/libs/config/assets.config.js'

import httpInterceptor from '@/libs/common/http.interceptor.js'
import indexInterceptor from '@/libs/common/index.interceptor.js'
import indexPropto from '@/libs/common/index.propto.js'
import routeInterceptor from '@/libs/common/route.interceptor.js'
import localStorage from '@/libs/common/local.storage.js'
import httpApi from '@/libs/common/http.api.js'
import globalFunc from '@/libs/utils/common.js'

import uView from "uview-ui";
// import weixin from '@/utils/jwx.js'
import vuexStore from '@/store/$u.mixin.js'
import mpShare from 'uview-ui/libs/mixin/mpShare.js'
import indexMixin from '@/libs/mixin/index.mixin.js'

const install = function(Vue, i18n){
	Vue.use(uView);
	
	uni.$u.$config = EvnConfig
	
	uni.$u.$assets = AssetsConfig
    
    // 一些基本原型对象方法覆盖处理
    Vue.use(indexPropto)
    
    // 本地持久缓存管理
    Vue.use(localStorage)
    
	// 公共函数
	Vue.use(globalFunc)

	/**
	 * 文字显示
	 * @param {String} text 
	 * @param {String} candidate 备选项
	 */
	Vue.prototype.$text = function(text, candidate = ''){
		return this.$u.func.isNotNull(text) ? text : this.$u.func.isNotNull(candidate) ? candidate : ''
	}
    
	/**
	 * 项目图片地址拼接
	 * @param {String} hash 地址目录路径，如携带http域名，则不会匹配 href和 EvnConfig.imageUrl
	 * @param {String} href 域名，不传则拼接 EvnConfig.imageUrl 
	 */
	Vue.prototype.$imgurl = function(hash, href = ''){
		if(hash){
			return this.$u.func.isFullWebLink(hash) ? hash : (href || EvnConfig.imageUrl) + hash
		}else {
			return '' // 可以设置统一无图占位图
		}
	}
	
	// vuex
	Vue.mixin(vuexStore);
	
	// 引入uView对小程序分享的mixin封装
	Vue.mixin(mpShare)
	
	// 基础混淆
	Vue.mixin(indexMixin)
	
	// 国际化
	uni.$t = str => i18n.t(str)
	
	// 微信SDK
	// #ifdef H5
	// Vue.use(weixin, app)
	// #endif
	
	// http拦截器
	Vue.use(httpInterceptor)
	
	// 路由拦截器
	Vue.use(routeInterceptor)
	
	// 常用api拦截器
	Vue.use(indexInterceptor)
	
	// http接口API集中管理
	Vue.use(httpApi)
	
}

export default {
	install
}
